class WebSocketClient {
    constructor() {
      this.socket = null;
    }
  
    connect() {
      this.socket = new WebSocket('ws://localhost:5173/ws');
  
      this.socket.addEventListener('open', (event) => {
        console.log('已连接到服务器');
        this.socket.send('你好，我是客户端');
      });
  
      this.socket.addEventListener('message', (event) => {
        console.log('收到消息: ' + event.data);
      });
  
      this.socket.addEventListener('close', (event) => {
        console.log('与服务器断开连接');
      });
  
      this.socket.addEventListener('error', (event) => {
        console.log('发生错误: ', event);
      });
    }
  
    disconnect() {
      this.socket.close();
    }
  }
  
  export default WebSocketClient;
  